package Service

import (
	"context"
	"google.golang.org/grpc"
	"selfService/ginWeb/Service/pbfiles"
	"selfService/tool"
)

type PersonService struct {

}

var presonAddr = tool.GetConf().PresonAddr

// rpc 调用个人服务的注册接口
func (this *PersonService) CreateUser(i *service.CreateUserByPhoneRequest)(*service.CreateUserByPhoneResponse, error) {
	conn,err := grpc.Dial(presonAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	personClient := service.NewInterestServiceClient(conn)
	result,err := personClient.CreateUser(context.Background(),i)
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//rpc get_login(loginin_request) returns (login_response);    // 传入phone和password 返回信息
func (this *PersonService) GetLogin(i *service.LogininRequest)(*service.LoginResponse, error) {
	conn,err := grpc.Dial(presonAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	personClient := service.NewInterestServiceClient(conn)
	result,err := personClient.GetLogin(context.Background(),i)
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//rpc get_indi_authority(Indi_authority_request) returns(Indi_authority_response); //传入id 查询个人权限列表
func (this *PersonService) GetIndiAuthority(i *service.IndiAuthorityRequest)(*service.IndiAuthorityResponse, error) {
	conn,err := grpc.Dial(presonAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	personClient := service.NewInterestServiceClient(conn)
	result,err := personClient.GetIndiAuthority(context.Background(),i)
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//rpc Get_stuInfo(Stu_info_request) returns (Stu_info_response); // 传入id 查询学生信息
func (this *PersonService) GetStuInfo(i *service.StuInfoRequest)(*service.StuInfoResponse, error) {
	conn,err := grpc.Dial(presonAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	personClient := service.NewInterestServiceClient(conn)
	result,err := personClient.GetStuInfo(context.Background(),i)
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//rpc Get_userInfo(GetUserInfoByid_request) returns(login_response);//传入id 返回个人信息
func (this *PersonService) GetUserInfo(i *service.GetUserInfoByidRequest)(*service.LoginResponse, error) {
	conn,err := grpc.Dial(presonAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	personClient := service.NewInterestServiceClient(conn)
	result,err := personClient.GetUserInfo(context.Background(),i)
	if err!=nil {
		return nil,err
	}
	return result,nil
}

//rpc UpdateUserInfo(UpdateUserInfo_request) returns(UpdateUserInfo_response); // 修改用户资料
func (this *PersonService) UpdateUserInfo(i *service.UpdateUserInfoRequest)(*service.UpdateUserInfoResponse, error) {
	conn,err := grpc.Dial(presonAddr,grpc.WithInsecure())
	if err!=nil {
		return nil,err
	}
	personClient := service.NewInterestServiceClient(conn)
	result,err := personClient.UpdateUserInfo(context.Background(),i)
	if err!=nil {
		return nil,err
	}
	return result,nil
}